<?php
namespace App\Adshopuser\Models;
use Common\BaseModel;
class BShopGoods extends BaseModel
{
    public $res;
    public $expire;

    public function initialize()
    {
        parent::initialize();
        $this->setSource('b_shop_goods');
    }


    public function lists($params)
    {
        $page = intval($params['page']);
        $size = intval($params['limit']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $condition = '';
        if (isset($params['status']) && !empty($params['status'])) {
            if ($params['status'] == 2) {
                $condition .= "status = 0";
            } else {
                $condition .= "status ={$params['status']}";
            }
        }
        if (isset($params['category_id']) && !empty($params['category_id'])) {
            $condition .= " and category_id = {$params['category_id']}";
        }
        if (isset($params['category_child_id']) && !empty($params['category_child_id'])) {
            $condition .= " and category_child_id = {$params['category_child_id']}";
        }
        if (isset($params['name']) && !empty($params['name'])) {
            $condition .= " and name lick '%{$params['name']}%'";
        }
        $cate_list = $this::find(
            array(
                $condition,
                "order"  => 'id desc',
                'limit'  => $size,
                'offset' => $page
            )
        )->toarray();
//        //直接获取最后一条sql语句
//        echo $this->di->get('profiler')->getLastProfile()->getSQLStatement();
//        exit;
        $count         = $this::count($condition);
        $list['list']  = $cate_list;
        $list['total'] = $count;
        return $list;
    }

    public function getList($params)
    {
        $page = intval($params['page']);
        $size = intval($params['page_size']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $condition = "status = 1 and category_id = {$params['category_id']}";
        return $this::find(
            array(
                $condition,
                "order"  => 'id desc',
                'limit'  => $size,
                'offset' => $page
            ))->toarray();
    }


    public function platform_data($params=[]){
        $conditions="shop_id={$params['shop_id']}";
        $goods_count = $this->count(array(
            $conditions,
        ));
        return $goods_count;
    }
}
